package com.zhelun.demo.activity;

import android.net.http.SslError;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.zhelun.demo.R;

import butterknife.BindView;
import demo.bocweb.com.sdk.base.activity.BaseActivity;

/**
 * Created by zhelun on 2018/1/18.
 */
@Route(path = "/movie/info_activity")
public class MovieInfoActivity extends BaseActivity {
    @BindView(R.id.webview)
    WebView webview;
    @Autowired
    public String url;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_movie_info;
    }

    @Override
    protected void initData() {
        super.initData();

        ARouter.getInstance().inject(this);
        webview.loadUrl(url);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                setTitle(view.getTitle());
            }

            //
            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                // handler.cancel();// Android默认的处理方式
                handler.proceed();// 接受所有网站的证书
                // handleMessage(Message msg);// 进行其他处理
            }

        });

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (webview != null) {
            webview.destroy();
        }
    }

    @Override
    public void onBackPressed() {
        if (webview != null) {
            if (webview.canGoBack()) {
                webview.goBack();
            } else {
                finish();
            }
        }
    }
}
